package org;

import java.text.SimpleDateFormat;
import java.util.Date;

import database.DatabaseHelper;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.database.sqlite.SQLiteDatabase;


/**
 * @author 10107896
 * 
 */
public class Globals {

	public static SQLiteDatabase sqlDB;

	public static Boolean performingPendingRequest = false;

	public static SharedPreferences sharedPrefs;
	public static SharedPreferences.Editor sharedPrefsEditor;

	public static Boolean isLocked = false;
	public static String pin;

	public static String dateAndTime = "EEE. MMM dd, yyyy, hh:mmaa";

	public static String trackingId = "-1";
	
	public static Date lastPauseTime = null;
	
	public static Boolean oldUser=false;

	public static String packageName(Context ctx) {
		try {
			PackageManager pm = ctx.getPackageManager();
			PackageInfo packageInfo = pm
					.getPackageInfo(ctx.getPackageName(), 0);
			return packageInfo.packageName;
		} catch (NameNotFoundException e) {
			return "com.envisionmoible.reyoflight";
		}
	}

	public static void initialize(Activity act) {
		// Initialize SharedPreference
		sharedPrefs = act.getApplicationContext().getSharedPreferences(
				Consts.PREFS_NAME, 0);
		sharedPrefsEditor = sharedPrefs.edit();

		// Get Tracking ID

		// Initialize DB
		DatabaseHelper myDbHelper = DatabaseHelper.getInstance(act
				.getApplicationContext().getApplicationContext());

		try {
			sqlDB = myDbHelper.openDataBase();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	
	}


	public static boolean pushEnabled = true;

	public static Date stringToDate(String strDate) {
		SimpleDateFormat formatter;
		formatter = new SimpleDateFormat("EEE. MMM dd, yyyy");
		try {
			return (Date) formatter.parse(strDate);
		} catch (java.text.ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	public static String dateToString(Date strDate) {
		SimpleDateFormat formatter;
		formatter = new SimpleDateFormat("EEE. MMM dd, yyyy");
		return (String) formatter.format(strDate);
	}

	public static String timeToString(Date strDate) {
		SimpleDateFormat formatter;
		formatter = new SimpleDateFormat("hh:mm aa");
		return (String) formatter.format(strDate);
	}

	public static Date stringToTime(String strTime) {
		SimpleDateFormat formatter;
		formatter = new SimpleDateFormat("hh:mm aa");
		try {
			return (Date) formatter.parse(strTime);
		} catch (java.text.ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	public static Date stringToDate(String strDate, String format) {
		SimpleDateFormat formatter;
		formatter = new SimpleDateFormat(format);
		try {
			return (Date) formatter.parse(strDate);
		} catch (java.text.ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	public static String dateToString(Date strDate, String format) {
		SimpleDateFormat formatter;
		formatter = new SimpleDateFormat(format);
		return (String) formatter.format(strDate);
	}


}
